package com.easy_buy.repository;


import com.easy_buy.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Date;



@Repository
public class AopRepositoryImpl implements AopRepository {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int setOnLine(User user) {
        try {
            String sql = "UPDATE user SET LoginTime = ?,OnLineYes = 1 WHERE UCode = ?";
            Date now = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat();
            sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
            String loginTime = sdf.format(now);
            String uCode = user.getUcode();
            int rows = jdbcTemplate.update(sql, loginTime, uCode);
            return rows;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
